package org.allen.mst4j.service.impl;

import java.util.Arrays;

import org.allen.mst4j.common.Constants;
import org.allen.mst4j.dao.PilotsMapper;
import org.allen.mst4j.dao.UserMapper;
import org.allen.mst4j.domain.User;
import org.allen.mst4j.sysBean.ResultBean;
import org.allen.mst4j.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = false,propagation = Propagation.REQUIRED,timeout = Constants.DB_TIMEOUT)
public class UserServiceImpl extends BaseServiceImpl implements UserService{

	@Autowired
	protected UserMapper mapper;
	
	@Autowired
	protected PilotsMapper pilotsMapper;

	public ResultBean insert(User obj) {
		DEBUG("插入数据 " + obj.toString());

		mapper.insertReturnKey(obj);
		
		// 插入机师数据
		obj.getPilots().setUserid(obj.getId());
		byte[] skill = new byte[64];
		Arrays.fill(skill, (byte)0);
		obj.getPilots().setSkill(skill);
		pilotsMapper.insert(obj.getPilots());
		return ResultBean.RESULT_SUCCESS(obj);
	}
}
